package com.pucheng.bracelet.app.database.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy.REPLACE
import androidx.room.Query
import androidx.room.Update
import com.pucheng.bracelet.data.bean.SleepBean
import kotlinx.coroutines.flow.Flow

@Dao
interface SleepDao {

    @Insert(onConflict = REPLACE)
    suspend fun insert(vararg bean: SleepBean)

    @Insert(onConflict = REPLACE)
    suspend fun insertToList(list: List<SleepBean>)

    @Update
    suspend fun update(vararg bean: SleepBean)

    @Query("SELECT * FROM sleep")
    fun getAll(): LiveData<List<SleepBean>>

    @Query("SELECT * FROM sleep where date>=datetime('now','start of day','-7 day','weekday 1') AND date<datetime('now','start of day','+0 day','weekday 1')")
    fun getWeekData(): LiveData<List<SleepBean>>

    @Query("SELECT * FROM sleep order by date desc limit 0,7")
    fun get7Days(): LiveData<List<SleepBean>>

    @Query("SELECT * FROM sleep WHERE date = :date")
    fun getDataToDate(date:String): LiveData<SleepBean>

}